using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using UWBGL_WinForms_Lib1;
using UWBGL_XNA_Lib13;

namespace XNA_SceneNode
{
	public class CPrimitiveArm : UWB_Primitive
	{
		CArm mArm;
		UWB_BoundingBox mBound;

		public CPrimitiveArm(float x, float y, float z)
		{
			mBound = new UWB_BoundingBox();

			mArm = new CArm(new Vector3(x, y, z), "Arm");
			mArm.setVelocity(new Vector3(UWB_Utility.UWB_RandomNumber(-0.1f, 0.1f),
																	UWB_Utility.UWB_RandomNumber(-0.6f, -0.9f), 0.0f));
			setVelocity(mArm.getVelocity());
			UWB_XFormInfo xf = mArm.getXFormInfo();
			float s = UWB_Utility.UWB_RandomNumber(0.3f, 0.6f);
			xf.setScale(new Vector3(s, s, 1.0f));
			mArm.setXFormInfo(xf);
		}

		public override void update(float elapsedSeconds)
		{
			Vector3 v = getVelocity();
			v.Y -= UWB_Utility.UWB_RandomNumber(2.5f, 4.0f);    // some acceleration

			mArm.setVelocity(getVelocity()); // From Primitive to SceneNode

			mArm.moveNodeByVelocity(elapsedSeconds);
			UWB_XFormInfo xf = mArm.getXFormInfo();
			float deg = (elapsedSeconds * UWB_Utility.UWB_RandomNumber(20.0f, 60.0f)) + xf.getRotationInDegrees();
			xf.setRotationDegrees(deg);
			mArm.setXFormInfo(xf);

			UWB_SceneNode p = mArm.GetPalmNode();
			xf = p.getXFormInfo();
			deg = (elapsedSeconds * UWB_Utility.UWB_RandomNumber(-50.0f, -100.0f)) + xf.getRotationInDegrees();
			xf.setRotationDegrees(deg);
			p.setXFormInfo(xf);
		}
		public override UWB_BoundingVolume getBoundingVolume(eLevelofDetail lod)
		{
			UWB_XNADrawHelper d = new UWB_XNADrawHelper();
			UWB_BoundingBox b = mBound;
			mArm.getNodeBounds(mArm, ref b, d, true);
			return b;
		}
		protected override void drawPrimitive(eLevelofDetail lod, UWB_DrawHelper drawHelper)
		{
			mArm.draw(lod, drawHelper);
		}
	}
}

